﻿//********************************************************************
// 
//  file:  frmAllContracts.cs
// 
//  (C) Copyright 2010, Diomede Corporation
//  All rights reserved
// 
//  Use, modification, and distribution is subject to   
//  the New BSD License (See accompanying file license.txt).
// 
//********************************************************************

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Diomede.SDK;
using data.diomedestorage.com;

namespace Diomede.Explorer
{
    public partial class frmAllContracts : Form
    {
        public frmAllContracts()
        {
            InitializeComponent();
        }

        public frmAllContracts(ISession session)
        {
            InitializeComponent();
            Session = session;
        }

        public ISession Session { get; set; }

        public Contract[] SelectedContract { get; private set; }

        private void frmAllContracts_Load(object sender, EventArgs e)
        {
            loadContracts();
        }

        void loadContracts()
        {
            IPurchasingManagement p = Session as IPurchasingManagement;
            ContractsExecResult result = p.GetAllContracts();
            if (result.Status == Diomede.SDK.Enums.ExecutionResults.Success)
            {
                grid.DataSource = result.Contracts;
                grid.Columns[0].Visible = false;
            }
            else
            {
                MessageBox.Show(this, result.Message, "Error");
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
            List<Contract> list = new List<Contract>();
            foreach (DataGridViewRow row in grid.SelectedRows)
            {
                list.Add(row.DataBoundItem as Contract);
            }
            SelectedContract = list.ToArray();
            Close();
        }
    }
}
